<template>
  <div>
    <div>
      <!--<image src="/static/assets/banner_img.png" class="Banner"></image>-->
      <van-tabs :active="active" custom-class="tabs" @change="onChange">
        <van-tab title="拼团中">
          <div style="height:5px;"></div>
          <div v-if="fightingGroups.length>0">
            <div class='content-list' v-for="(group,idx) in fightingGroups" :key="idx" @click="seeFightGroup(group.id)">
              <div class='list-image-box'>
                <image class="list-image"
                 :src="group.picture_url"
                  ></image>
              </div>
              <div class='issue-name'>
                <div style="height:25px;color:#444444;font-size:15px;font-weight:bold;">{{group.title}}</div>
                <div style="height:20px;color:#aaaaaa;font-size:13px;width:100%;">
                  ￥{{group.price/100}} <span style="color:#aaaaaa;font-size:10px;text-decoration:line-through;padding-left:8px;">￥{{group.original_price/100}}</span>
                </div>
                <div style="height:20px;line-height:25px;">
                  <van-row>
                    <van-col span="5" style="background:red;">
                      <div class="group-item-num">{{group.people_num}}人团</div>
                    </van-col>
                    <van-col span="14">
                      <div style="width:100%;height:20px;">
                        <progress class="progress" :percent="group.fighting_num/group.people_num*100" stroke-width="4" activeColor="#FDB4BB" border-radius="3" />
                      </div>
                    </van-col>
                    <van-col span="5">
                      <span style="font-size:10px;color:#aaaaaa;padding-left:8px;">{{group.fighting_num}}/{{group.people_num}}</span>
                      <van-icon class="arrow-icon" color="#aaaaaa" name="arrow" size="18px"/>
                    </van-col>
                  </van-row>
                </div>
                <div style="font-size:12px;color:#aaaaaa;">有效期至：{{group.end_time}}</div>
              </div>
            </div>
          </div>
          <div v-else style="text-align:center;">
            <image class="not_group" src="/static/assets/not_group.png"></image>
            <div style="text-align:center;font-size:15px;color:#B7BDC9;">没有拼团记录，快去拼团吧</div>
            <div class="btn" @click="goFightGroup()">我要拼团</div>
          </div>
        </van-tab>
        <van-tab title="拼团成功">
          <div style="height:5px;"></div>
          <div v-if="successGroups.length>0">
            <div class='content-list' v-for="(group,idx) in successGroups" :key="idx" @click="seeFightGroup(group.id)">
              <div class='list-image-box'>
                <image class="list-image"
                 :src="group.picture_url"
                  ></image>
              </div>
              <div class='issue-name'>
                <div style="height:25px;color:#444444;font-size:15px;font-weight:bold;">{{group.title}}</div>
                <div style="height:20px;color:#aaaaaa;font-size:13px;width:100%;">
                  ￥{{group.price/100}} <span style="color:#aaaaaa;font-size:10px;text-decoration:line-through;padding-left:8px;">￥{{group.original_price/100}}</span>
                </div>
                <div style="height:20px;line-height:25px;">
                  <van-row>
                    <van-col span="5" style="background:red;">
                      <div class="group-item-num">{{group.people_num}}人团</div>
                    </van-col>
                    <van-col span="14">
                      <div style="width:100%;height:20px;">
                        <progress class="progress" :percent="group.fighting_num/group.people_num*100" stroke-width="4" activeColor="#FDB4BB" border-radius="3" />
                      </div>
                    </van-col>
                    <van-col span="5">
                      <span style="font-size:10px;color:#aaaaaa;padding-left:8px;">{{group.fighting_num}}/{{group.people_num}}</span>
                      <van-icon class="arrow-icon" color="#aaaaaa" name="arrow" size="18px"/>
                    </van-col>
                  </van-row>
                </div>
                <div style="font-size:12px;color:#aaaaaa;">{{group.updated}} 已成功</div>
              </div>
            </div>
          </div>
          <div v-else style="text-align:center;">
            <image class="not_group" src="/static/assets/not_group.png"></image>
            <div style="text-align:center;font-size:15px;color:#B7BDC9;">没有拼团记录，快去拼团吧</div>
            <div class="btn" @click="goFightGroup()">我要拼团</div>
          </div>
        </van-tab>
        <van-tab title="拼团失败">
          <div style="height:5px;"></div>
          <div v-if="failGroups.length>0">
            <div class='content-list' v-for="(group,idx) in failGroups" :key="idx" @click="seeFightGroup(group.id)">
              <div class='list-image-box'>
                <image class="list-image"
                 :src="group.picture_url"
                  ></image>
              </div>
              <div class='issue-name'>
                <div style="height:25px;color:#444444;font-size:15px;font-weight:bold;">{{group.title}}</div>
                <div style="height:20px;color:#aaaaaa;font-size:13px;width:100%;">
                  ￥{{group.price/100}}<span style="color:#aaaaaa;font-size:10px;text-decoration:line-through;padding-left:8px;">￥{{group.original_price/100}}</span>
                </div>
                <div style="height:20px;line-height:25px;">
                  <van-row>
                    <van-col span="5" style="background:red;">
                      <div class="group-item-num">{{group.people_num}}人团</div>
                    </van-col>
                    <van-col span="14">
                      <div style="width:100%;height:20px;">
                        <progress class="progress" percent="40" stroke-width="4" activeColor="#FDB4BB" border-radius="3" />
                      </div>
                    </van-col>
                    <van-col span="5">
                      <span style="font-size:10px;color:#aaaaaa;padding-left:8px;">{{group.fighting_num}}/{{group.people_num}}</span>
                      <van-icon class="arrow-icon" color="#aaaaaa" name="arrow" size="18px"/>
                    </van-col>
                  </van-row>
                </div>
                <div style="font-size:12px;color:#aaaaaa;">已失效</div>
              </div>
            </div>
          </div>
          <div v-else style="text-align:center;">
            <image class="not_group" src="/static/assets/not_group.png"></image>
            <div style="text-align:center;font-size:15px;color:#B7BDC9;">没有拼团记录，快去拼团吧</div>
            <div class="btn" @click="goFightGroup()">我要拼团</div>
          </div>
        </van-tab>
      </van-tabs>
    </div>
  </div>
</template>

<script>
import {formatTime} from '@/utils/index'
import api from '@/utils/api'
import { mapState, mapActions ,mapGetters } from 'vuex'
export default {
  data () {
    return {
      active:0,
      fightingGroups:[],
      successGroups:[],
      failGroups:[],
      groupHeight:0
    }
  },
  computed: {
    ...mapGetters([
      'user'
    ]),
  },
  methods: {
    seeFightGroup(id){
      console.log('999999999999')
      wx.navigateTo({url:"/pages/activity/group/group_detail?fight_group_id="+id})
    },
    goFightGroup(){
      wx.switchTab({url:"/pages/activity/index"})
    },
    onChange(event) {
      //event.target.title
      console.log('event=>',event.mp.detail.index)
      this.active = event.mp.detail.index
    },
  },
  /*beforeMount(){
    var self = this
    wx.getSystemInfo({
      success(res){
        self.groupHeight = res.windowHeight-270
      }
    })
  },*/
  async onShow(){
    console.log('111')
    let fightingGroups = await api.findGroupByStatus({user_id:this.user.id,status:'fighting'})
    if (fightingGroups.code == 0) {
      fightingGroups.data.forEach(item=>{
        item.end_time = formatTime(item.end_time)
      })
      this.fightingGroups = fightingGroups.data
    }
    let successGroups = await api.findGroupByStatus({user_id:this.user.id,status:'success'})
    if (successGroups.code == 0) {
      successGroups.data.forEach(item=>{
        item.updated = formatTime(item.updated)
      })
      this.successGroups = successGroups.data
    }
    let failGroups = await api.findGroupByStatus({user_id:this.user.id,status:'fail'})
    if (failGroups.code == 0) {
      this.failGroups = failGroups.data
    }
  }
}
</script>

<style>
page{
  background: #F1F3F8;
}
.Banner{
  height: 150px;
  width: 100%;
  margin-bottom: -5px;
}
.content-list{
  margin-bottom: 15px;
  height: 110px;
  display:flex;
  background: #fff;
}
.list-image-box{
  margin-left: 10px;
  width:100px;
  height:110px;
  vertical-align: middle;
  display: table-cell;
  vertical-align: middle;
  text-align: center;
}
.list-image{
  width:90px;
  height: 90px;
  vertical-align: middle;
  margin-top: 10px;
}
.issue-name{
  width:220px;
  margin-top:10px;
  margin-left: 20px;
  margin-bottom: 10px;
}
.choose_buy{
  width: 50px;
  height: 25px;
  float: right;
}
.seemore-btn{
  height: 50px;
  line-height: 50px;
  text-align: center;
  color: #aaaaaa;
  margin-right: 15px;
  margin-left: 15px;
  border-top: 2px solid #F2F2F2;
  font-size: 17px;
}
.group-item-num{
  display: inline-block;
  background: #FDB4BB;
  font-size: 9px;
  color: #fff;
  height: 18px;
  line-height:18px;
  width: 35px;
  text-align: center;
  border-radius: 9px;
}
.progress{
  position: relative;
  top: 15px;
}
.arrow-icon{
  position: relative;
  bottom: 15px;
  right: -20px;
}
.not_group{
  width: 120px;
  height: 120px;
  margin-top: 20px;
  margin-bottom: 10px;
}
.btn{
  height: 40px;
  line-height: 40px;
  width:100px;
  color: #8F96A0;
  font-size: 15px;
  text-align: center;
  background: #FFF;
  border-radius: 20px;
  margin: 30px auto ;
  border: 1px solid #CDD2E0;
}
</style>
